#include "py32f030_hal.h"


void systick_delay_ms(uint16_t ms)
{
    uint32_t u32end;
    uint32_t u32Cnt;
    u32Cnt=ms;
    SysTick->LOAD = 0xFFFFFF;
    SysTick->VAL  = 0;
    SysTick->CTRL |= 0x01;

    while(u32Cnt-- > 0)
    {
        SysTick->VAL  = 0;
        u32end = 0x1000000 - SystemCoreClock/1000;
        while(SysTick->VAL > u32end)
        {
            ;
        }
    }

    SysTick->CTRL &= ~0x01;
    SysTick->VAL = 0;

}

void systick_delay_us(uint16_t us)
{
    uint32_t u32end;
    uint32_t u32Cnt;
    u32Cnt=us;
    SysTick->LOAD = 0xFFFFFF;
    SysTick->VAL  = 0;
    SysTick->CTRL |= 0x01;

    while(u32Cnt-- > 0)
    {
        SysTick->VAL = 0;

        u32end = 0x1000000 - SystemCoreClock/100000;
        while(SysTick->VAL > u32end)
        {
            ;
        }
    }

    SysTick->CTRL &= ~0x01;
    SysTick->VAL = 0;
}



